<template>
	<view class="page">
		<view class="tabs">
			<u-tabs :list="list" :is-scroll="false" active-color="#006747" inactive-color="#666666" :current="current" @change="change"></u-tabs>
		</view>
		<view class="line"></view>
		<view class="list">
			<view class="listX" v-for="(v, k) in listData" :key="k">
				<view class="list_details">
					<view class="list_le">
						<view>{{v.change_type_value}}</view>
						<view>{{v.create_time}}</view>
					</view>
					<view :class="v.change_type == 1 || v.change_type == 5 ? 'list_ri2' : 'list_ri'">
						<text>{{v.change_money}}</text>
					</view>
					<image class="shenhe" v-if="v.check_status == 1" src="/static/talent/user/examine1.png"></image>
					<image class="shenhe" v-if="v.check_status == 2" src="/static/talent/user/examine2.png"></image>
					<image class="shenhe" v-if="v.check_status == 3" src="/static/talent/user/examine3.png"></image>
				</view>
				<view v-if="v.check_reason != ''" class="reason">{{v.check_reason}}</view>
			</view>
		</view>
		<view v-if="listData.length == 0" style="margin: 20rpx 0;">
			<u-empty style="margin: 20rpx 0;" text="没有更多了" mode="list"></u-empty>
		</view>
		<view style="padding: 20rpx 0;">
			<u-loadmore v-if="last_page > 1" :status="status" :icon-type="iconType" :load-text="loadText" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					{
						name: '全部'
					},
					{
						name: '收入记录'
					},
					{
						name: '支出记录'
					}
				],
				current: 0,
				yueType: 2,
				listData: [],
				last_page: 1,
				page: 1,
				refresh: false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多了'
				}
			}
		},
		methods: {
			change(index) {
				this.current = index;
				if (this.current == 0) {
					this.yueType = 2
				}
				if (this.current == 1) {
					this.yueType = 3
				}
				if (this.current == 2) {
					this.yueType = 4
				}
				this.page = 1
				this.refresh = true
				uni.showLoading({
					title: '加载中'
				})
				this.balanceInfo()
			},
			// 获取消费记录
			balanceInfo() {
				this.$api.post(global.apiUrls.myBalanceList, {
					type: 1,
					page: this.page
				}).then(res => {
					// console.log(res)
					uni.hideLoading()
					uni.stopPullDownRefresh()
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page
						if (this.refresh) {
							this.listData = res.data.data.data
							this.refresh = false
						} else {
							this.listData = this.listData.concat(res.data.data.data)
			
						}
						this.listData.forEach((v, k) => {
							v.change_money = v.change_money.substring(0, v.change_money.length - 3)
						})
			
					} else {
						// this.$message.info(res.data.msg)
					}
				})
			},
		},
		onLoad() {

		},
		onShow() {
			uni.showLoading({
				title: '加载中'
			})
			this.balanceInfo()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.refresh = true
			this.balanceInfo()
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			this.refresh = false
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.balanceInfo()
			}, 500)
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		background-color: #FFFFFF;
		color: #333333;
		.tabs {
			
		}
		.line {
			width: 100%;
			height: 20rpx;
			background: #f2f2f1;
		}
		.list {
			padding: 0 32rpx;
			.listX {
				padding: 32rpx 0;
				border-bottom: 1rpx solid #f2f2f1;
				
				.list_details {
					display: flex;
					position: relative;
				}
				.list_le {
					width: 80%;
					view:first-child {
						font-size: 32rpx;
						color: #1C2921;
						margin-bottom: 24rpx;
					}
					view:last-child {
						font-size: 24rpx;
						color: #999999;
					}
				}
				.list_ri {
					text-align: right;
					width: 20%;
					padding-top: 32rpx;
					color: #EB5D03;
					text:first-child {
						font-size: 24rpx;
					}
					text:last-child {
						font-size: 32rpx;
						font-weight: bold;
					}
				}
				.list_ri2 {
					text-align: right;
					width: 20%;
					padding-top: 32rpx;
					color: #333333;
					text:first-child {
						font-size: 24rpx;
					}
					text:last-child {
						font-size: 32rpx;
						font-weight: bold;
					}
				}
				.shenhe {
					width: 90rpx;
					height: 70rpx;
					position: absolute;
					right: 40rpx;
					top: 16rpx;
					
				}
				.reason {
					margin-top: 24rpx;
					padding: 16rpx 20rpx;
					font-size: 24rpx;
					color: #999999;
					background: #F6F7F9;
				}
			}
		}
	}
</style>
